from abc import ABC

from Alibb.handlers import BaseHandler
from apps.api.get_offer import GetOfferApi
from tools.auth import authenticated_async


class SelectOfferHandler(BaseHandler, ABC):

    @authenticated_async
    async def get(self, page, size):
        api = GetOfferApi(self.current_user['access_token'],
                          self.application.session,
                          self.application.settings['app_key'])

        param = {
            "pageNo": page,
            "pageSize": size,
            "statusList": ["published"]
        }

        status_code, resp = await api.post(param)

        if status_code == 401:
            self.set_status(401)
            return await self.finish({"error": "用户授权过期"})

        await self.finish(resp)
